<?
//<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
require ("s_inc.php");
$rows = 20;
$page	  = $_REQUEST['page']?$_REQUEST['page']:1;
//權限
admin_main::pageChk('cats_set');
?>
<?php require("s_head.tpl.php"); ?>
<?
$db_admin = &new db($scfg['db']['admin']);
$table 	  = 'ad_index_big_img';
if($_POST || $_GET['act'] == 'del')
{
	ini_set("upload_max_filesize", "20M"); 
	ini_set("memory_limit", "32M"); 
	ini_set("post_max_size", "24M");
	
	
	$act = $_REQUEST['act'];
	//print_r($_POST);
	if($act == 'modify')
	{
		$id 	= (int)$_REQUEST['id'];
		$bind 	= array(
			'subject'=>$_POST['subject'],
			'url' =>$_POST['url'],
			'chk_yn' =>$_POST['chk_yn'],
			'save_time'=>time(),
			'author'=>$_POST['author'],
			'begin'=>strtotime($_POST['begin']),
			'end'=>strtotime($_POST['end'])
		);
		$rs = $db_admin->update($table,$bind," id =? ",$id);
		if($rs)
		{
		 	g::dir(UP_IMG_DIR."adm/index_big_img");
			$fileName = UP_IMG_DIR."adm/index_big_img/".$id.".jpg";
			if(move_uploaded_file($_FILES['img']['tmp_name'], $fileName))
			{
				$rs=img::cut($fileName,ADM_UPIMAGES_W,ADM_UPIMAGES_H,2,95,$fileName);
				if(!$rs[0])
				{
					echo g::msg($rs[1]);
				}
			}
			echo g::msg("成功：更新公告成功!");			
		}else
		{
		    echo g::msg("提示：没有更新！可能是你没有新的改动，如改动请稍重试！");
		}
	}elseif($act == 'add')
	{
		$bind = array(
			'subject'	=>$_POST['subject'],
			'url' 		=>$_POST['url'],
			'chk_yn' 	=>$_POST['chk_yn'],
			'save_time'	=>time(),
			'author'	=>$_POST['author'],
			'begin'		=>strtotime($_POST['begin']),
			'end'		=>strtotime($_POST['end'])
		);
		$id = $db_admin->insert($table,$bind);
		if($id)
		{		 	 
			g::dir(UP_IMG_DIR."adm/index_big_img");
			$fileName = UP_IMG_DIR."adm/index_big_img/".$id.".jpg";
			if(move_uploaded_file($_FILES['img']['tmp_name'], $fileName))
			{
				$rs=img::cut($fileName,ADM_UPIMAGES_W,ADM_UPIMAGES_H,2,95,$fileName);
				if(!$rs[0])
				{
					echo g::msg($rs[1]);
				}
			}else
			{
				echo g::msg("提示：图上传失败!"); 
			}
			echo g::msg("成功：添加有成功!");   
			g::gowin("?");
			exit();
		}else
		{
		    echo g::msg("提示：系統忙请稍后重试!");
		}
	}elseif($act == 'del')
	{
		$id = (int)$_REQUEST['id'];
		if($id)
		{
		 	$rs = $db_admin->delete($table," id =? ",$id);
			//echo  $db_help->getsql();
			//exit();
		 	if($rs)
		 	{
		 	    $fileName = UP_IMG_DIR."adm/index_big_img/".$id.".jpg";
				unlink($fileName);
				echo g::msg("成功：删除成功！");
		 	}else
		 	{
		 	 	echo g::msg("失败：不存在，或系统忙请稍后再试!");   
		 	}    
		}else
		{
		    echo g::msg("提示：参数有误，请误非法操作!");
		}
		g::gowin();
	}
}
//////////////////////////////////////////////////////////////////////////////////
$act = $_GET['act'];
if($act == 'list' || empty($act))
{
    $where      = array();
    $pg			= pg::sp($db_admin,$table,$where,$page,$rows);
	$rs 		= $db_admin->dataArray("select * from {$table} {$where['where']} order by id desc limit {$pg['begin']},".$rows,$where['bind']);
?>
<table width="100%"  border="0" cellpadding="4" cellspacing="1" class="tableoutline">
	<tr>
	<td colspan="4" class="tbhead">首页大图广告管理</td>
  </tr>
  <tr class="_data_" style="font-weight:bold;">
	<td width="65%">標題与图片</td>
	<td width="10%">录入者</td>
    <td width="20%">时间</td>
    <td width="5%">操作</td>
  </tr>
  <?
   foreach($rs as &$v)
   {  
   		$fileName = surl::get("img")."adm/index_big_img/".$v['id'].".jpg";	
  ?>
  <tr class="_data_">
    <td align="left">标题:<b><?=$v['subject']?></b><br />
    <img src="<?=$fileName?>?<?=time()?>" /> <br />
    URL:<?=$v['url']?></td>
    <td align="left"><?=$v['author']?></td>
    <td align="left">录入:<?=g::time($v['save_time'],1)?><br />
      开始:<?=g::time($v['begin'],1)?>
    <br />
    结束:<?=g::time($v['end'],1)?></td>
    <td align="left"><a href="?act=modify&id=<?=$v['id']?>">修改</a><br />      
    <a href="?act=del&id=<?=$v['id']?>" onClick="return oAdmin.msgYn();">刪除</a></td>
  </tr>
  <?
   }
  ?>
</table>
<br />
<form method="post" enctype="multipart/form-data" onSubmit="return XypForm(this)">
<table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr>
        <td colspan="2" class="tbhead">添加首页大图广告</td>
      </tr>
	  <tr class="_data_">
		<td align="right">标题：</td>
		<td align="left"> 
		 <input name="subject" require="1" value="<?=$_POST['subject']?>" type="text" id="subject" size="50" maxlength="32"></td>
	  </tr>
	  <tr class="_data_">
        <td width="14%" align="right">图片：        </td>
        <td width="86%" align="left"><input type="file" name="img" id="img" /></td>
  </tr>
      <tr class="_data_">
        <td width="14%" align="right">录入者：        </td>
        <td width="86%" align="left"><input name="author"  require="1" type="text" id="author" size="30" maxlength="30" value="<?=admin_main::getMaster()?>"></td>
      </tr>
  <tr class="_data_">
        <td align="right" valign="top">目标URL：</td>
        <td align="left">
      <input name="url" type="text" id="url" size="50" /></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">投放时间：</td>
        <td align="left">
        从
          <input name="begin" type="text" id="begin" size="20"  value="<?=g::time()?>" />
          到
          <input name="end" type="text" id="end" size="20" value="<?=g::time(time()+3600*24*30)?>" />
          如:从2007-02-08 17:45:00到2007-03-08 17:45:00</td>
      </tr>
  <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput">
        <input type="reset" class="bginput">
        
        <input name="act" type="hidden" id="act" value="add"></td>
      </tr>
</table>
</form>

<?
}elseif($act == 'modify')
{
	$id = (int)$_REQUEST['id'];
	$rs = $db_admin->row("select * from {$table} where id=? ",$id);
?>
<form method="post" enctype="multipart/form-data" onSubmit="return XypForm(this)">
<table width="100%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
        <tr>
        <td colspan="2" class="tbhead">添加首页大图广告</td>
      </tr>
	  <tr class="_data_">
		<td align="right">标题：</td>
		<td align="left">
		 <input name="subject" require="1" value="<?=$rs['subject']?>" type="text" id="subject" size="50" maxlength="32"></td>
	  </tr>
	  <tr class="_data_">
        <td width="14%" align="right">
        <?
        $fileName = surl::get("img")."adm/index_big_img/".$rs['id'].".jpg";
		?>
        图片：  </td>
        <td width="86%" align="left"><img src="<?=$fileName?>?<?=time()?>" /><br />
			<input type="file" name="img" id="img" /></td>
      </tr>
      <tr class="_data_">
        <td width="14%" align="right">录入者：        </td>
        <td width="86%" align="left"><input name="author"  require="1" type="text" id="author" size="20" maxlength="30" value="<?=$rs['author']?>"></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">目标URL：</td>
        <td align="left">
        <input name="url" type="text"  value="<?=$rs['url']?>" id="url" size="50" /></td>
      </tr>
      <tr class="_data_">
        <td align="right" valign="top">投放时间：</td>
        <td align="left"> 从
          <input name="begin"  value="<?=date("Y-m-d H:i:s",$rs['begin'])?>" type="text" id="begin" size="20" />
          到
          <input name="end" value="<?=date("Y-m-d H:i:s",$rs['end'])?>"  type="text" id="end" size="20" />
          如:从2007-02-08 17:45:00到2007-03-08 17:45:00</td>
      </tr>
      <tr class="_data_">
        <td>&nbsp;</td>
        <td><input type="submit" class="bginput">
        <input type="reset" class="bginput">        
        <input name="act" type="hidden" id="act" value="modify"></td>
      </tr>
</table>
</form>
<? }?>
<? include("s_copyRight.tpl.php"); ?>